package org.simple.framework.boot.controller;

import org.simple.framework.data.entity.Identifiable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;

import java.io.Serializable;
import java.security.Principal;
import java.util.List;

/**
 * 项目名称：simple-framework
 * 类名称：ModelAllController
 * 类描述：ModelAllController
 * 创建时间：2018/9/6
 *
 * @author sisyphus   (E-mail:1620657419@qq.com)
 * @version v1.0
 */
public interface ModelAllController<E extends Identifiable<ID>, ID extends Serializable> extends ModelController<E, ID> {

    void handleAll(Principal principal);

    @GetMapping("/all")
    default List<E> all(Principal principal) {
        handleAll(principal);
        return getRepository().findAll();
    }

    @GetMapping("/all/page")
    default Page<E> all(Pageable pageable, Principal principal) {
        handleAll(principal);
        return getRepository().findAll(pageable);
    }

}
